# +----------------------------------------------------------------------
# | ChatWork智能聊天办公系统
# +----------------------------------------------------------------------
# | 软件声明: 本系统并非自由软件,未经授权任何形式的商业使用均属非法。
# | 版权保护: 任何企业和个人不允许对程序代码以任何形式任何目的复制/分发。
# | 授权要求: 如有商业使用需求,请务必先与版权所有者取得联系并获得正式授权。
# +----------------------------------------------------------------------
# | Author: ChatWork Team <2474369941@qq.com>
# +----------------------------------------------------------------------
from typing import Union, List
from pydantic import BaseModel, Field
from fastapi import Query


class MusicConfigIn(BaseModel):
    engine: str = Query(..., pattern=r"^(suno)$", description="音乐引擎")


class MusicRecordSearchIn(BaseModel):
    """ 音乐记录搜索参数 """
    page_no: int = Query(default=1, gt=0, description="当前页码")
    page_size: int = Query(default=15, gt=0, le=200, description="每页条数")
    engine: str = Query(..., pattern=r"^(suno)$", description="音乐引擎")
    status: Union[int, str, None] = Query(default=None, description="生成状态: [0=待生成, 1=生成中, 2=成功, 3=失败]")


class MusicRecordDetectionIn(BaseModel):
    """ 音乐记录检测参数 """
    ids: List[str] = Field(default=[], description="记录编号")


class MusicRecordCodeIn(BaseModel):
    """ 音乐记录编号参数 """
    code: str = Field(..., max_length=32, description="音乐编号")


class MusicGenerateIn(BaseModel):
    """ 音乐生成参数"""
    engine: str = Field(..., pattern=r"^(suno)$", description="音乐引擎")
    mode: str = Field(..., pattern=r"^(muse|lyric)$", description="生成模式: [灵感=muse, 歌词=lyric]")
    title: str = Field(..., min_length=1, max_length=100, description="歌曲标题")
    prompt: str = Field(..., min_length=1, max_length=2000, description="歌曲描述")
    styles: List[int] = Field(default=[], description="风格ID")
    tags: str = Field(default="", description="风格词汇")
    mv: str = Field(..., max_length=50, description="模型版本")
    make_instrumental: bool = Field(default=False, description="纯音乐")

    class Config:
        json_schema_extra = {
            "example": {
                "engine": "suno",
                "mode": "muse",
                "title": "歌曲标题",
                "prompt": "歌曲描述",
                "styles": [1, 2],
                "tags": "heartfelt, folk, nostalgic",
                "mv": "chirp-v3-5",
                "make_instrumental": False
            }
        }

    @classmethod
    def messages(cls):
        return {
            "title.min_length": "请填写歌曲名称",
            "title.max_length": "歌曲名称不能超出100个字符",
            "prompt.min_length": "请填写歌曲描述",
            "prompt.max_length": "歌曲描述不能超出2000个字符",
        }


"""--------------- Separator ---------------"""


class MusicConfigVo(BaseModel):
    options: List[dict] = Field(description="应用选项")
    configs: dict = Field(description="配置参数")


class MusicStylesVo(BaseModel):
    """ 音乐风格Vo """
    id: int = Field(description="风格ID")
    image: str = Field(description="图标")
    name: str = Field(description="名称")
    value: str = Field(description="值")


class MusicRecordsVo(BaseModel):
    """ 音乐记录Vo """
    id: int = Field(description="记录ID")
    code: str = Field(description="记录编号")
    title: str = Field(description="歌曲标题")
    prompt: str = Field(description="歌曲描述")
    tags: str = Field(description="歌曲风格")
    make_instrumental: bool = Field(description="纯音乐")
    cover_url: str = Field(description="音乐封面")
    audio_url: str = Field(description="音乐地址")
    duration: int = Field(description="音乐时长")
    lyric: str = Field(description="歌曲歌词")
    use_points: int = Field(description="消耗积分")
    is_free: int = Field(description="免费调用: [0=否, 1=是]")
    status: int = Field(description="生成状态: [0=等待中, 1=执行中, 2=成功, 3=失败]")
    share_status: int = Field(description="分享广场: [0=待审, 1=审核通过, 2=审核拒绝]")
    share_result: str = Field(description="分享结果")
    fail_reason: str = Field(description="失败原因")
    create_time: str = Field(description="创建时间")

    class Config:
        json_schema_extra = {
            "example": {

            }
        }
